<?php

namespace fize\think\listener;

use think\facade\Config;
use think\facade\Env;

/**
 * 加载不同环境配置
 */
class LoadConfig
{

    public function handle()
    {
        $app_status = Env::get('app_status');
        if ($app_status) {
            if (is_dir(root_path() . 'config-' . $app_status)) {
                $dir = root_path() . 'config-' . $app_status . DIRECTORY_SEPARATOR;
                $files = scandir($dir);
                foreach ($files as $file) {
                    if (pathinfo($file, PATHINFO_EXTENSION) == 'php') {
                        Config::load($dir . $file, pathinfo($file, PATHINFO_FILENAME));
                    }
                }
            }
        }
    }
}
